package com.health.controller.backend;

import com.health.common.PageBean;
import com.health.common.Result;
import com.health.dto.SetmealQueryDTO;
import com.health.pojo.Setmeal;
import com.health.service.SetmealService;
import com.huaweicloud.oss.HuaWeiCloudObsUploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 套餐控制器层
 *
 * @author zgp
 * @version V1.0
 * @date 2025-01-19 19:34
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private HuaWeiCloudObsUploadUtil huaWeiCloudObsUploadUtil;

    @PostMapping("/findPage")
    public PageBean<Setmeal> getPageList(@RequestBody SetmealQueryDTO setmealQueryDTO) {
        return setmealService.getPageList(setmealQueryDTO);
    }

    @PostMapping("/upload")
    public Result<String> setmealImgUpload(MultipartFile imgFile) throws IOException {
        String url = huaWeiCloudObsUploadUtil.upload(imgFile.getBytes(), imgFile.getOriginalFilename());
        return Result.success(url);
    }

    @PostMapping("/add")
    public Result<String> addSetmeal(@RequestBody Setmeal setmeal, @RequestParam("checkgroupIds") List<Integer> checkgroupIds){
        setmealService.addSetmeal(setmeal, checkgroupIds);
        return Result.success();
    }
}
